package top.hcode.hoj.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author orangej
 * @since 2025/1/6
 */
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
    @Bean(value = "admin")
    public Docket adminApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("管理后台api接口")
                        .description("# 管理后台api接口")
                        .termsOfServiceUrl("https://oj-rui-ya.com/api/admin")
                        .version("1.0")
                        .build())
                .groupName("管理后台")  // 分组名称
                .select()
                .apis(RequestHandlerSelectors.basePackage("top.hcode.hoj.controller.admin"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean(value = "front")
    public Docket frontApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("前台api接口")
                        .description("# 前台api接口")
                        .termsOfServiceUrl("https://oj-rui-ya.com/api")
                        .version("1.0")
                        .build())
                .groupName("前台接口")  // 分组名称
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("top.hcode.hoj.controller"))
                .paths(PathSelectors.regex("^(?!/api/admin/).*$"))
                .build();
    }
}
